﻿#include "panel.h"
#include "ui_panel.h"

Panel::Panel(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Panel)
{
    ui->setupUi(this);

    stock=nullptr;
    stockView=nullptr;
    reject=nullptr;
    rejectView=nullptr;
    loss=nullptr;
    lossView=nullptr;
    mass=nullptr;
    massView=nullptr;
    epiboly=nullptr;
    epibolyView=nullptr;
}

Panel::~Panel()
{
    delete ui;
}

void Panel::on_btn_stock_clicked()
{
    if(stock == nullptr)
    {
        stock=new Stock(this);
        if(!stock->init())
        {
            displayError();
            stock=nullptr;
            return;
        }
    }
    stock->show();
}

void Panel::on_btn_loss_clicked()
{
    if(loss == nullptr)
    {
        loss=new Loss(this);
        if(!loss->init())
        {
            displayError();
            loss=nullptr;
            return;
        }
    }
    loss->show();
}

void Panel::on_btn_stockview_clicked()
{
    if(stockView==nullptr)
        stockView=new StockView(this);
    stockView->show();
}

void Panel::on_btn_lossview_clicked()
{
    if(lossView==nullptr)
        lossView=new LossView(this);
    lossView->show();
}

void Panel::on_btn_mass_clicked()
{
    if(mass == nullptr)
        mass=new Mass(this);
    mass->show();
}

void Panel::on_btn_massview_clicked()
{
    if(massView==nullptr)
        massView=new MassView(this);
    massView->show();
}

void Panel::on_btn_reject_clicked()
{
    if(reject==nullptr)
    {
        reject=new Reject(this);
        if(!reject->init())
        {
            displayError();
            reject=nullptr;
            return;
        }
    }
    reject->show();
}

void Panel::on_btn_rejectView_clicked()
{
    if(rejectView == nullptr)
        rejectView=new RejectView(this);
    rejectView->show();
}

void Panel::on_btn_epiboly_clicked()
{
    if(epiboly==nullptr)
    {
        epiboly=new Epiboly(this);
        if(!epiboly->init())
        {
            displayError();
            epiboly=nullptr;
            return;
        }
    }
    epiboly->show();
}

void Panel::on_btn_epibolyView_clicked()
{
    if(epibolyView==nullptr)
        epibolyView=new EpibolyView(this);
    epibolyView->show();
}

void Panel::displayError()
{
    QMessageBox::critical(this,QStringLiteral("致命错误"),QStringLiteral("组件无法启动，请检查配置文件！"),QMessageBox::Ok);
}
